package player.ui.browse;

import java.io.File;
import java.util.Vector;

import javax.swing.Icon;
import javax.swing.JComponent;

import player.ThumbManage;
import player.Tools;
import player.mplayer.MediaInfo;
import player.mplayer.MediaManager;
import player.ui.playlist.PlayListManage;
import player.ui.playlist.PlayListModel;

import net.miginfocom.swing.MigLayout;

public class PlayListPanel extends JComponent {
	private static final long serialVersionUID = -6337114161243011774L;
	ListPanel ImgPanel;
	PlayListManage pm;
	PlayListPanel(){
		super();
		setLayout(new MigLayout("insets 0 0 0 0"));
		setBorder(Tools.creatDefaultBorder());
		ImgPanel=new ListPanel();
		add(ImgPanel,"width :20480:,height :20480:");
	}
	
	void openPlayList(PlayListManage pm,PlayListModel plm){
		ImgPanel.removeAll();
		
		Vector<MediaInfo> list=plm.getList();
		int index=0;
		for(MediaInfo mi:list){
			File file=new File(mi.mediaPath);
			Icon icon=Tools.getFileIcon(file);
			if(!ThumbManage.containImg(file.getAbsolutePath())){
	    		ThumbManage.tryMplayImg(file.getAbsolutePath());
	    	}
			File[] imfFiles=ThumbManage.getImgFiles(file.getAbsolutePath());
			ImgPanel.addItem(pm,plm,MediaManager.getMediaInfo(file.getAbsolutePath()),index,icon,file.getName(),imfFiles);
			index++;
		}
		
		repaint();
		validate();
	}
	
	
	
}
